<!-- 企业编辑弹窗 -->
<template>
  <ele-modal
    form
    :width="800"
    :model-value="modelValue"
    title="退定信息"
    @update:modelValue="updateModelValue"
  >
    <div class="tools">
      <el-button type="info" :loading="loading" @click="save(0)">
        退定
      </el-button>
      <el-button type="warning" :loading="loading" @click="save(1)">
        强行退定
      </el-button>
      <el-button type="danger" :loading="loading" @click="save(2)">
        后台退定（不处罚）
      </el-button>
    </div>
    <apply-record :member-id="data.member_id" />
  </ele-modal>
</template>

<script setup>
  import { ref, watch } from 'vue';
  import { EleMessage } from 'ele-admin-plus/es';
  import { jobCancel } from '@/api/company';
  import ApplyRecord from '@/views/student/components/apply-record.vue';

  const emit = defineEmits(['done', 'update:modelValue']);

  const props = defineProps({
    /** 弹窗是否打开 */
    modelValue: Boolean,
    /** 修改回显的数据 */
    data: Object
  });

  /** 表格选中数据 */
  const selections = ref([]);

  /** 提交状态 */
  const loading = ref(false);

  /** 表单数据 */
  const form = ref({
    id: void 0, // 处罚事项的id
    title: '',
    reason: '',
    amount: '',
    job_id: 0,
    site_id: 0,
    code: ''
  });

  /** 保存编辑 */
  const save = (admin) => {
    var requestData = {
      id: props.data.id,
      admin
    };

    jobCancel(requestData)
      .then((msg) => {
        EleMessage.success(msg);
        updateModelValue(false);
        emit('done');
      })
      .catch((e) => {
        console.log(e);
      });
  };

  /** 更新modelValue */
  const updateModelValue = (value) => {
    emit('update:modelValue', value);
  };

  watch(
    () => props.modelValue,
    (modelValue) => {
      if (modelValue) {
        form.value.id = void 0;
        form.value.amount = '';
        form.value.reason = '';
        form.value.title = '';

        // credit.value = props.data.work_date_time > 0;
      }
    }
  );
</script>

<style scoped>
  .tools {
    display: flex;
    margin-bottom: 10px;
    .input {
      margin-right: 8px;
    }
  }
  .foot {
    margin-top: 10px;
    span {
      margin-left: 14px;
      font-size: 12px;
    }
  }
  .mr {
    margin-right: 8px;
  }
</style>
